﻿
namespace Thor.WebRole.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web.DomainServices;
    using System.Web.Ria;
    using System.Web.Ria.Services;
    using Thor.Common;
    using Thor.Domain;
    using Thor.Domain.Configuration;


    // TODO: Create methods containing your application logic.
    [EnableClientAccess()]
    public class TimeZoneDomainService : DomainService
    {
        public List<Thor.Common.TimeZone> GetTimeZones()
        {
            TimeZoneManager manager = new TimeZoneManager();
            return manager.GetTimeZones();
        }

        public List<Thor.Common.TimeZone> GetDistinctCalendarTimeZones()
        {
            var result = new List<Thor.Common.TimeZone>();

            var timeZones = CalendarHelper.GetDistinctCalendarTimeZones();

            if (timeZones != null)
            {
                foreach (var timeZone in timeZones)
                    result.Add(new Thor.Common.TimeZone() { Name = timeZone });
            }

            return result;
        }

        public Thor.Common.TimeZone GetCalendarTimeZone(string calendarEmail)
        {
            Thor.Common.TimeZone result = null;

            var svc = new CalendarManagerDomainService();
            var calendar = svc.GetCalendar(calendarEmail);

            if (calendar != null)
                result = new Thor.Common.TimeZone() { Name = calendar.TimeZone };

            return result;
        }
    }
}


